package com.kdd.campus.common.util;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @Auther: fcp
 * @Date: 2020/4/26 19:58
 * @Description:
 */
public class PropertyUtils  {
    //保存系统文件。
    private static String sysFile = "application.yml";
    private static Properties Sysproperties ;
    static {
        Sysproperties = PropertyUtils.getProperties(sysFile);
    }

    /**
     * 获取指定路径下的配置文件信息
     *
     * @param configPath
     * @return
     */
    public static Properties getProperties(String configPath) {
        Properties pros = new Properties();
        try {
            ClassLoader cl = ClassLoader.getSystemClassLoader();
            ClassLoader.getSystemClassLoader().getResource(configPath);
            pros.load(new InputStreamReader(cl.getResourceAsStream(configPath), "UTF-8"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return pros;
    }

    public static String getConfigByName(String key){
        return Sysproperties.getProperty(key);
    }
}
